int[ , ] x = new int[3, 3];
int[ , ] x = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
double[,] data = { { 160, 179, 165, 183, 145 },{ 45, 80, 60, 75, 53 } };
int People = data.GetLength(1); // 計算陣列的列數,這將是人數
for (int i = 0; i < People; i++)
{
double height = data[0, i] / 100.0; // 將身高轉換為公尺
double weight = data[1, i];
double bmi = weight / (height* height);
string label; // 判斷BMI範圍並提供標示
if (bmi < 18.5)
{
label = "過輕";
}
else if (bmi < 24)
{
label = "適中";
}
else
{
label = "過重";
}
Console.WriteLine("Person " + (i + 1) + ": BMI = " + bmi.ToString("F2") + " , " + label);
}
※以上資料如有錯誤請多指教
書名:程式設計基本功與實務範例解析:使用C#(第三版)(附範例光碟)